﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Whoever.Website.BusinessLogic
{
    public class MessageManager
    {
        protected void SendAEmail(BusinessObject.Message message,String senderAddress,String senderPassword,String receiverAddress)
        {
            var email = new Framework.Utilities.Email();
            var emailSender = new Framework.Utilities.EmailSender();
            var emailBuilder = new StringBuilder();

            emailBuilder.AppendLine(String.Format("Nombre: {0}", message.SenderName));
            emailBuilder.AppendLine(String.Format("Apellido: {0}", message.SenderSurname));
            emailBuilder.AppendLine(String.Format("Email: {0}", message.SenderEmail));
            emailBuilder.AppendLine(String.Format("Telefono: {0}", message.SenderPhone));
            emailBuilder.AppendLine(String.Format("Asunto: {0}", message.Subject));
            emailBuilder.AppendLine(String.Format("Mensaje: {0}", message.Text));

            email.SenderAddress = senderAddress;
            email.SenderPassword = senderPassword;
            email.ReceiverAddress = receiverAddress;
            email.SmtpServer = "mail.whoever-systems.com";
            email.IsHtmlBody = false;//En el futuro se puede enviar contenido html en el mail para una mayor estetica o para nuestras publicidades
            email.Subject = message.Subject;
            email.Body = emailBuilder.ToString();

            emailSender.Send(email);//Testear posibles excepciones
        }

        public void SendEmail(BusinessObject.Message message)
        {
            //Se envia el mismo mensaje a nuestras casillas
            SendAEmail(message, "Contact@whoever-systems.com", "Bondiola123", "contact@whoever-systems.com");
            SendAEmail(message, "Contact@whoever-systems.com", "Bondiola123", "Matias.Cuestas@whoever-systems.com");
            SendAEmail(message, "Contact@whoever-systems.com", "Bondiola123", "Jonathan.Luis@whoever-systems.com");
        }

        public void Register()//Se guarda el mensaje en la base de datos (Diseñar db e implementar)
        {
            
        }

    }
}
